﻿@RenderPage(view)
@functions{
    private string action;
    private string id;
    private string view;
    protected override void InitializePage()
    {
    // Get first verb from Url and use as action
    var action = UrlData[0].ToLower(); 
    // Get second verb and use it as id.
    var id = UrlData[1];
    // Example:
    // mysite.com/projects/edit/0
    // UrlData[0] returns "edit"
    // UrlData[1] returns "0"
     
    // Now act on the action verb:   
    switch(action) {      
       
        case "delete":
            if (!IsPost)
            {        
                var GetDataModelFromDb = "MockData for record # " + id;
                Page.Model = GetDataModelFromDb;               
                view = "/Customer/_Delete.cshtml";       
            }
            else
            {
                //<strong>Handle delete</strong>
            }           
            break;
        case "main":
            //if(!IsPost){
                //get the lookup values
                
                Page.Mode="0";
                Customer cSearch = new Customer();
                cSearch.FName=UtilityManager.GetVal(Request["fname"]);
                cSearch.MName=UtilityManager.GetVal(Request["mname"]);
                cSearch.LName=UtilityManager.GetVal(Request["lname"]);
                cSearch.HasDuplicate=Convert.ToInt32(Request["hasDup"]);
                cSearch.Bdate=UtilityManager.GetDateVal(Request["bdate"]);
                cSearch.Region="AP";
                cSearch.Country="PH";
                cSearch.BusAddCountry="PH";
                cSearch.PermAddCountry="PH";
                
                cSearch.IDType=UtilityManager.GetVal(Request["idType"]);
                cSearch.IDNumber=UtilityManager.GetVal(Request["idNumber"]);
                cSearch.MobileNo=UtilityManager.GetVal(Request["mobileCC"]) +"|"+ UtilityManager.GetVal(Request["mobileAC"]) +"|"+ UtilityManager.GetVal(Request["mobileNo"]);
                cSearch.LandLineNo=UtilityManager.GetVal(Request["landlineCC"]) +"|"+ UtilityManager.GetVal(Request["landlineAC"]) +"|"+ UtilityManager.GetVal(Request["landlineNo"]);
                cSearch.CurrMailZip=UtilityManager.GetVal(Request["zip"]);
                Page.Customer=cSearch;
                
                view="/Customer/_CustomerForm.cshtml";
           // }
            break;
    
            
        case "search":
           
            if(!IsPost){
                Page.Mode=0;
                Page.SearchCount=0;
                view="/Customer/_Search.cshtml";
            }else{
                 
                 Customer cust = new Customer();
                 cust.FName = Request["fname"];
                 cust.LName=Request["lname"];
                 cust.Bdate=Convert.ToDateTime(Request["bdate"]);
                 var query = CustomerManager.SearchCustomer(cust);
                 Page.SearchCount = query.Count;
                 Page.SearchResult = query;
                 Page.Mode=1;
                 view="/Customer/_Search.cshtml";
            }
            break;
         case "edit":
             //get customer details
            Page.Customer= CustomerManager.GetCustomer(id);
            Page.Mode="4";
            //Page.Title="Edit Customer";
            view = "/Customer/_CustomerForm.cshtml"; 
            break;
         case "view":
             //get customer details
            Page.Customer= CustomerManager.GetCustomer(id);
            Page.Mode="3";
            //Page.Title="Edit Customer";
            view = "/Customer/_CustomerForm.cshtml"; 
            break;
            
        default:
            view = "/Customer/_Menu.cshtml";       
            break;
        }
    }
}
